<template>
  <div class="flex">
    <!-- <ga-link
      :loading="record?.status === 'syncing'"
      @click="operationsHandleSelect('sync')"
    >
      同步
    </ga-link> -->
    <!-- <ga-link status="danger" @click="operationsHandleSelect('delete')">删除</ga-link> -->
    <ga-link @click="operationsHandleSelect('edit')">重启</ga-link>
    <ga-link @click="operationsHandleSelect('edit')">查看密码</ga-link>
    <ga-dropdown position="br" @select="operationsHandleSelect">
      <ga-link> <icon-more style="cursor: pointer" /></ga-link>
      <template #content>
        <ga-dsubmenu value="option-1">
          <template #default>实例状态</template>
          <template #content>
            <ga-doption>开机</ga-doption>
            <ga-doption>关机</ga-doption>
            <ga-doption>重启</ga-doption>
            <ga-doption>销毁</ga-doption>
          </template>
        </ga-dsubmenu>
        <ga-dsubmenu value="option-2">
          <template #default>实例设置</template>
          <template #content>
            <ga-doption>编辑标签</ga-doption>
            <ga-doption>创建快照</ga-doption>
          </template>
        </ga-dsubmenu>
        <ga-dsubmenu value="option-3">
          <template #default>资源调整</template>
          <template #content>
            <ga-doption>更改配置</ga-doption>
            <ga-doption>磁盘扩容</ga-doption>
            <ga-doption>添加磁盘</ga-doption>
          </template>
        </ga-dsubmenu>
        <ga-doption>迁移</ga-doption>
        <ga-doption>网卡配置</ga-doption>
        <ga-doption>克隆实例</ga-doption>
        <ga-doption>制作镜像</ga-doption>
        <ga-doption>绑定镜像</ga-doption>
        <ga-doption>控制台</ga-doption>
        <ga-doption>IP</ga-doption>
        <ga-dsubmenu value="option-4">
          <template #default>蓝鲸</template>
          <template #content>
            <ga-doption>安装AGENT</ga-doption>
            <ga-doption>执行记录</ga-doption>
          </template>
        </ga-dsubmenu>
        <ga-dsubmenu value="option-5">
          <template #default>插件</template>
          <template #content>
            <ga-doption>执行记录</ga-doption>
          </template>
        </ga-dsubmenu>
        <ga-doption>注册堡垒机</ga-doption>
        <ga-doption>同步</ga-doption>
      </template>
    </ga-dropdown>
  </div>
</template>

<script setup>
import { toRefs } from "vue";
import { deleteList, sync } from "@/api/platformMgt";
import { Message } from "@garco-design/web-vue";
import { deleteModal } from "@/hooks/deleteModal";

const props = defineProps({
  record: {
    type: Object,
    required: true,
  },
});
const { record } = toRefs(props);
const emits = defineEmits(["handleEditOrAdd", "fetchData"]);
const operationsHandleSelect = async (action) => {
  if (action === "edit") {
    emits("handleEditOrAdd");
  } else if (action === "delete") {
    deleteModal(`确定要删除当前数据-[${record.value?.name}]`, async () => {
      try {
        await deleteList(record.value?.id);
        Message.success("删除成功");
        emits("fetchData");
      } catch (err) {
        console.log(err);
      }
    });
  } else if (action === "sync") {
    try {
      const { code } = await sync(record.value.id);
      if (code === 20000) Message.success("操作成功，后台同步中");
      record.value.status = "syncing";
    } catch (e) {
      console.log(e);
    }
  }
};
</script>

<style scoped lang="less"></style>
